<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" ipt="IE=edge">
    <meta name="viewport" ipt="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        textarea {
            outline: none;
        }
    </style>
</head>

<body>
    <div id="app">
        <textarea name="" id="" cols="30" rows="10" v-model="ipt" autofocus></textarea>
        <button @click="send">发表评论</button>
        <p v-for="(item,index) in arr">
            {{arr[index].text}} {{arr[index].date}} {{arr[index].like}}
            <button @click="btn1(index)">点赞</button>
            <button @click="btn2(index)">置顶</button>
            <button @click="btn3(index)">删除</button>
        </p>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>

    <script>
        let vm = new Vue({
            el: "#app",
            data: {
                ipt: "",
                arr: [],
            },
            methods: {
                send() {
                    if (this.ipt == "") return;
                    this.arr.push({
                        text: this.ipt,
                        date: "11月",
                        like: 0
                    });
                    this.ipt = "";
                },
                btn1(idx) {
                    this.arr[idx].like++
                },
                btn2(idx) {
                    this.arr.unshift(this.arr[idx])
                    this.arr.splice(idx + 1, 1);
                },
                btn3(idx) {
                    this.arr.splice(idx, 1)
                }
            }
        })
    </script>
</body>

</html>